package Method;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.nio.charset.StandardCharsets;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import java.sql.SQLException;
public class Isexist{
    public boolean judge(String checkid) {
        int flag = 0;

        java.sql.Connection conn = null;
        java.sql.Statement sqlStmt = null; //语句对象
        java.sql.ResultSet sqlRst = null; //结果集对象
        try {
            InitialContext context = new InitialContext();
            DataSource dataSource =
                    (DataSource) context.lookup("jpa/DSTest");
            conn = dataSource.getConnection();

            sqlStmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
//执行Sql语句
System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            String sqlQuery = "select * from localdata where userid="+"'"+checkid+"'";
            sqlRst = sqlStmt.executeQuery(sqlQuery);
            System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
           // System.out.println(sqlRst.next());
        } catch (NamingException e) {

        } catch (SQLException e) {

        } finally {
            try {
               while (sqlRst.next()){ flag = 1;break;}
                System.out.println(sqlRst.getString("password"));
                if (sqlRst != null) {
                    sqlRst.close();
                }
                if (sqlStmt != null) {
                    sqlStmt.close();
                }
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException e) {
            }
            if (flag == 1) return true;
            else return false;
        }
    }
}
